All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.JTextPane

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----com.sun.java.swing.JComponent
                           |
                           +----com.sun.java.swing.text.JTextComponent
                                   |
                                   +----com.sun.java.swing.JEditorPane
                                           |
                                           +----com.sun.java.swing.JTextPane

public class JTextPane
extends JEditorPane
A text component that can be marked up with attributes that are represented graphically. This component models paragraphs that are composed of runs of character level attributes. Each paragraph may have a logical style attached to it which contains the default attributes to use if no overriden by attributes set on the paragraph or character run. Components and images may be embedded in the flow of text.

For the keyboard keys used by this component in the standard Look and Feel (L&F) renditions, see the JTextPane key assignments.

Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

See Also:
StyledEditorKit

Constructor Index

 o JTextPane()
Constructs a new JTextPane.
 o JTextPane(StyledDocument)
Constructs a new JTextPane, with a specified document model.

Method Index

 o addStyle(String, Style)
Adds a new style into the logical style hierarchy.
 o createDefaultEditorKit()
Creates the EditorKit to use by default.
 o getCharacterAttributes()
Fetches the character attributes in effect at the current location of the caret, or null.
 o getInputAttributes()
Gets the input attributes for the pane.
 o getLogicalStyle()
Fetches the logical style assigned to the paragraph represented by the current position of the caret, or null.
 o getParagraphAttributes()
Fetches the current paragraph attributes in effect at the location of the caret, or null if none.
 o getScrollableTracksViewportWidth()
Returns true if a viewport should always force the width of this Scrollable to match the width of the viewport.
 o getStyle(String)
Fetches a named non-null style previously added.
 o getStyledDocument()
Fetches the model associated with the editor.
 o getStyledEditorKit()
Gets the editor kit.
 o getUIClassID()
Returns the class ID for the UI.
 o insertComponent(Component)
Inserts a component into the document as a replacement for the currently selected content.
 o insertIcon(Icon)
Inserts an icon into the document as a replacement for the currently selected content.
 o removeStyle(String)
Removes a named non-null style previously added to the document.
 o replaceSelection(String)
Replaces the currently selected content with new content represented by the given string.
 o setCharacterAttributes(AttributeSet, boolean)
Applies the given attributes to character content.
 o setDocument(Document)
Associates the editor with a text document.
 o setEditorKit(EditorKit)
Sets the currently installed kit for handling content.
 o setLogicalStyle(Style)
Sets the logical style to use for the paragraph at the current caret position.
 o setParagraphAttributes(AttributeSet, boolean)
Applies the given attributes to paragraphs.
 o setStyledDocument(StyledDocument)
Associates the editor with a text document.

Constructors

 o JTextPane
 public JTextPane()
Constructs a new JTextPane. A new instance of StyledEditorKit is created and set, and the document model set to null.

 o JTextPane
 public JTextPane(StyledDocument doc)
Constructs a new JTextPane, with a specified document model. A new instance of StyledEditorKit is created and set.

Parameters:
doc - the document model

Methods

 o getUIClassID
 public String getUIClassID()
Returns the class ID for the UI.

Returns:
the ID ("TextPaneUI")
Overrides:
getUIClassID in class JEditorPane
See Also:
getUIClassID, getUI
 o setDocument
 public void setDocument(Document doc)
Associates the editor with a text document. This must be a StyledDocument.

Parameters:
doc - the document to display/edit
Throws: IllegalArgumentException
if doc can't be narrowed to a StyledDocument which is the required type of model for this text component
Overrides:
setDocument in class JTextComponent
 o setStyledDocument
 public void setStyledDocument(StyledDocument doc)
Associates the editor with a text document. The currently registered factory is used to build a view for the document, which gets displayed by the editor.

Parameters:
doc - the document to display/edit
 o getStyledDocument
 public StyledDocument getStyledDocument()
Fetches the model associated with the editor.

Returns:
the model
 o replaceSelection
 public void replaceSelection(String content)
Replaces the currently selected content with new content represented by the given string. If there is no selection this amounts to an insert of the given text. If there is no replacement text this amounts to a removal of the current selection. The replacement text will have the attributes currently defined for input. If the document is not editable, beep and return. Then if the document is null, do nothing. If the content to insert is null or empty, ignore it.

This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.

Parameters:
content - the content to replace the selection with
Overrides:
replaceSelection in class JTextComponent
 o insertComponent
 public void insertComponent(Component c)
Inserts a component into the document as a replacement for the currently selected content. If there is no selection the component is effectively inserted at the current position of the caret. This is represented in the associated document as an attribute of one character of content.

Parameters:
c - the component to insert
 o insertIcon
 public void insertIcon(Icon g)
Inserts an icon into the document as a replacement for the currently selected content. If there is no selection the icon is effectively inserted at the current position of the caret. This is represented in the associated document as an attribute of one character of content.

This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.

Parameters:
g - the icon to insert
See Also:
Icon
 o addStyle
 public Style addStyle(String nm,
                       Style parent)
Adds a new style into the logical style hierarchy. Style attributes resolve from bottom up so an attribute specified in a child will override an attribute specified in the parent.

Parameters:
nm - the name of the style (must be unique within the collection of named styles). The name may be null if the style is unnamed, but the caller is responsible for managing the reference returned as an unnamed style can't be fetched by name. An unnamed style may be useful for things like character attribute overrides such as found in a style run.
parent - the parent style. This may be null if unspecified attributes need not be resolved in some other style.
Returns:
the new Style
 o removeStyle
 public void removeStyle(String nm)
Removes a named non-null style previously added to the document.

Parameters:
nm - the name of the style to remove
 o getStyle
 public Style getStyle(String nm)
Fetches a named non-null style previously added.

Parameters:
nm - the name of the style
Returns:
the style
 o setLogicalStyle
 public void setLogicalStyle(Style s)
Sets the logical style to use for the paragraph at the current caret position. If attributes aren't explicitly set for character and paragraph attributes they will resolve through the logical style assigned to the paragraph, which in term may resolve through some hierarchy completely independant of the element hierarchy in the document.

This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.

Parameters:
s - the logical style to assign to the paragraph, or null for no style
 o getLogicalStyle
 public Style getLogicalStyle()
Fetches the logical style assigned to the paragraph represented by the current position of the caret, or null.

Returns:
the style
 o getCharacterAttributes
 public AttributeSet getCharacterAttributes()
Fetches the character attributes in effect at the current location of the caret, or null.

Returns:
the attributes, or null
 o setCharacterAttributes
 public void setCharacterAttributes(AttributeSet attr,
                                    boolean replace)
Applies the given attributes to character content. If there is a selection, the attributes are applied to the selection range. If there is no selection, the attributes are applied to the input attribute set which defines the attributes for any new text that gets inserted.

This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.

Parameters:
attr - the attributes
replace - if true, then replace the existing attributes first
 o getParagraphAttributes
 public AttributeSet getParagraphAttributes()
Fetches the current paragraph attributes in effect at the location of the caret, or null if none.

Returns:
the attributes
 o setParagraphAttributes
 public void setParagraphAttributes(AttributeSet attr,
                                    boolean replace)
Applies the given attributes to paragraphs. If there is a selection, the attributes are applied to the paragraphs that intersect the selection. if there is no selection, the attributes are applied to the paragraph at the current caret position.

This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.

Parameters:
attr - the non-null attributes
replace - if true, replace the existing attributes first
 o getInputAttributes
 public MutableAttributeSet getInputAttributes()
Gets the input attributes for the pane.

Returns:
the attributes
 o getStyledEditorKit
 protected final StyledEditorKit getStyledEditorKit()
Gets the editor kit.

Returns:
the editor kit.
 o createDefaultEditorKit
 protected EditorKit createDefaultEditorKit()
Creates the EditorKit to use by default. This is implemented to return StyledEditorKit.

Returns:
the editor kit
Overrides:
createDefaultEditorKit in class JEditorPane
 o setEditorKit
 public final void setEditorKit(EditorKit kit)
Sets the currently installed kit for handling content. This is the bound property that establishes the content type of the editor.

Parameters:
kit - the desired editor behavior.
Throws: IllegalArgumentException
if kit is not a StyledEditorKit
Overrides:
setEditorKit in class JEditorPane
 o getScrollableTracksViewportWidth
 public boolean getScrollableTracksViewportWidth()
Returns true if a viewport should always force the width of this Scrollable to match the width of the viewport.

Returns:
true if a viewport should force the Scrollables width to match its own.
Overrides:
getScrollableTracksViewportWidth in class JEditorPane

All Packages  Class Hierarchy  This Package  Previous  Next  Index